import { takeEvery, call } from 'redux-saga/effects'
import { loginAPI } from 'api/login'
import { message } from 'antd'
import { Token, setToken, getToken } from 'utils/token'
export function* loginSaga() {
  yield takeEvery('login', function* ({ payload, props }) {
    try {
      const { data } = yield call(loginAPI, payload)
      setToken(data.token)
      message.success('登陆成功', 1, () => {
        props.history.push(props.location?.state?.pathname || '/home')
      })
    } catch (error) {
      message.error(error?.response?.data?.message)
    }
  })
}
